<?php

class Ajax extends Controller {

    function get_stats()
    {
        $this->load->helper('json');
        $this->load->model('Helping_model');
        $this->load->model('Stats_model');
        $mydata['stats'] = $this->Stats_model->get_stats();
        $mydata['helping'] = $this->Helping_model->get_helping();
        $mydata['stats'][0]['total_helping'] = count($mydata['helping']);
        $data['encoded_data'] = json_encode($mydata);
        $this->load->view('json_view', $data);
        //Checkear si tenemos que refrescar las estadísticas
      
    }

    function get_new()
    {
        $this->load->model('Need_model');
        $last_id = $this->input->post('last_id');
        $this->load->helper('json');
        $mydata['new_ids'] = $this->Need_model->count_after($last_id);
        $data['encoded_data'] = json_encode($mydata);
        $this->load->view('json_view', $data);
    }

    function set_helping()
    {
        $this->load->model('Helping_model');
        $id = $this->input->post('id');
        $mydata['result'] = $this->Helping_model->insert_helping($id);
        $data['encoded_data'] = json_encode($mydata);
        if ($mydata['result'])
                {
                    $this->load->model('Need_model');
                    $this->Need_model->update($id, "RESOLVIENDO", "", "");
                }
        $this->load->view('json_view', $data);
    }

    function unset_helping()
    {
        $this->load->model('Helping_model');
        $id = $this->input->post('id');
        $mydata = $this->Helping_model->remove_helping($id);
        $this->load->model('Need_model');
        $this->Need_model->update($id, "LLAMAR", "", "");
    }


}
?>
